window.onload=function(){
}
function getWeekSchedule(weekindex){
	//根据教学周生成课表
	user_data = JSON.parse(rwLS("r","str_jsonData"));
	if(user_data){
	    console.log("have data");
        result = user_data['result'];

        lessonList = result['lessonList'];
        scheduleList = result['scheduleList'];
        scheduleGroupList = result['scheduleGroupList'];
        lessonName={"test":"test"}
        for(lesson0 in lessonList){
            lessonName[lessonList[lesson0]['id']]=lessonList[lesson0]['courseName'];
		}

        userdata=[]
        for(l_obj1 in scheduleList){
            if(scheduleList[l_obj1]["weekIndex"]==weekindex){
                //for(var day= 0;day<7;day++){if(scheduleList[l_obj1]["weekday"] ==day){}}
                var rtjson=[{
                    "lessonID":scheduleList[l_obj1]["lessonId"],
                    "courseName":lessonName[scheduleList[l_obj1]["lessonId"]],
                    "teacher":scheduleList[l_obj1]["personName"],
                    "date":scheduleList[l_obj1]["date"],
                    "starttime":scheduleList[l_obj1]["startTime"],
                    "weekday":scheduleList[l_obj1]["weekday"],
                    "position":scheduleList[l_obj1]["room"]["nameZh"]
                    }];

                //console.log("data-----:"+rtjson[0]["courseName"]);
                userdata.push(rtjson);

            }
        }
	}else{
	    swal("请先加载课表！","","error");
	}

}
function getDayclass(weekDay){
    console.log("getDayclass");
    //getWeekSchedule(jiaoxuezhou());
    getWeekSchedule(12);
    todayclass=""
	for(class_obj in userdata){
	    if(userdata[class_obj][0]["weekday"] == 4){
                todayclass += userdata[class_obj][0]["courseName"] +"   ";
	    }
	}
	swal("今日课程",todayclass,"success");
}

function jiaoxuezhou(){
	var date = new Date();
	switch((date.getMonth()+1)) {
			case 5:
				if([3,4,5,6,7,8,9].includes(date.getDate())){
					return 9
				}else if([10,11,12,13,14,15,16].includes(date.getDate())){
					return 10
				}else if([17,18,19,20,21,22,23].includes(date.getDate())){
					return 11
				}else if([24,25,26,27,28,29,30].includes(date.getDate())){
					return 12
				}else if([31].includes(date.getDate())){
					return 13
				}
				break;
			case 6:
				if([1,2,3,4,5,6].includes(date.getDate())){
					return 13
				}else if([7,8,9,10,11,12,13].includes(date.getDate())){
					return 14
				}else if([14,15,16,17,18,19,20].includes(date.getDate())){
					return 15
				}else if([21,22,23,24,25,26,27].includes(date.getDate())){
					return 16
				}else if([28,29,30].includes(date.getDate())){
					return 17
				}
				break;
			case 7:
				if([1,2,3,4].includes(date.getDate())){
					return 18
				}else if([5,6,7,8,9,10,11].includes(date.getDate())){
					return 19
				}else if([12,13,14,15,16,17,18].includes(date.getDate())){
					return 20
				}else if([19,20,21,22,23,24,25].includes(date.getDate())){
					//已经是暑假了
					return 21
				}else if([26,27,28,29,30,61].includes(date.getDate())){
					return 22
				}
				break;
			default:
				return "none"
	} 
}

function getDay(days,flag2){
	var today = new Date();
	var targetday_milliseconds=today.getTime() + 1000*60*60*24*days;
	today.setTime(targetday_milliseconds);
	var tYear = today.getFullYear();
	var tMonth = today.getMonth();
	var tDate = today.getDate();
	tMonth = this.doHandleMonth(tMonth + 1);
	tDate = this.doHandleMonth(tDate);
	if(flag2=="day"){
		return tDate;
	}else if (flag2=="month"){
		return tMonth
	}else{
		return tYear+"-"+tMonth+"-"+tDate;
	}
}

function doHandleMonth(month){
	var m = month;
	if(month.toString().length == 1){
		m = "0" + month;
		}
	return m;
}

function rwLS(str,key,value){
	if(str == 'r'){
		return localStorage.getItem(key);
	}else if(str == 'w'){
		localStorage.setItem(key,value);
		return 1;
	}else if(str == 'rm'){
		localStorage.removeItem(key);
		return 2;
	}
}
